
public class parser {

	private String requeststring;
	private String[] requestarray;
	private httpobject h1;
	
	public parser()
	{
		h1 = new httpobject();
	}
	
	
	public httpobject parse(String constring)
	{
				
		if(constring != "")
		{
		requeststring = constring;
		
		requestarray = requeststring.split("\n");
		
		
		
		if(requestarray[0].contains("GET") && requestarray[0].contains("HTTP/1.1"))
		{
			h1.function = httpobject.functionType.GET;
			String []getRequestHeader = requestarray[0].split(" ");
			h1.filePath = getRequestHeader[1];
			String []getRequestHost = requestarray[1].split(" ");
			h1.multiHoming = getRequestHost[1].replace("\r", "");
		}
		else if(requestarray[0].contains("POST / HTTP/1.1"))
		{
			h1.function = httpobject.functionType.POST;
		}
		else if(requestarray[0].contains("HEAD / HTTP/1.1"))
		{
			h1.function = httpobject.functionType.HEAD;
		}
		else
		{
			try {
				throw( new Exception());
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		}
		return h1;
		
	}	
		
}
